<?php

declare(strict_types=1);

namespace App\Service;

use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerInterface;
use App\Exception\BusinessException;
use App\Constants\ErrorCode;

abstract class BaseService
{
    #[Inject]
    protected ContainerInterface $container;

    protected function returnError(string $message = 'error', int $code = ErrorCode::SERVER_ERROR)
    {
        throw new BusinessException($code,$message);
    }
    protected function error(string $message = '操作失败', int $code = 600): array
    {
        return [
            'code' => $code,
            'data' => ['date' => date('Y-m-d H:i:s')],
            'message' => $message,
        ];
    }

    protected function success($data = null, string $message = '操作成功'): array
    {
        return [
            'code' => 200,
            'data' => $data,
            'message' => $message,
        ];
    }
}